package com.wgo.precise.client.ui.view.editor.dummy;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;

import com.wgo.precise.client.ui.controller.RequirementPlugin;
import com.wgo.precise.client.ui.model.facade.IModelPersistable;
import com.wgo.precise.client.ui.model.facade.INodeParent;
import com.wgo.precise.client.ui.view.editor.AbstractPartsFormPage;
import com.wgo.precise.client.ui.view.session.LoginDialog;


/**
 * @author petterei
 *
 * @version $Id: DummyFormPage.java,v 1.2 2006-01-30 21:52:32 petterei Exp $
 */
public class DummyFormPage extends AbstractPartsFormPage {
	public final static String PAGE_ID = "modelDummy" ;
	public final static String PAGE_TITLE = "Dummy" ;
	private Hyperlink link = null;
	public DummyFormPage(FormEditor editor) {
		super(editor, PAGE_ID, PAGE_TITLE);
	}

	@Override
	protected void createFormContent(IManagedForm managedForm) {
		FormToolkit toolkit = managedForm.getToolkit(); 
		ScrolledForm form = managedForm.getForm();
		form.setText("Content not available.");
		form.setToolTipText("You are currently not logged in to server, please log in to get access.");
//		Composite body = toolkit.createComposite(form);
		Composite body = form.getBody();
		
		GridLayout layout = new GridLayout();
		layout.marginWidth = 10;
		layout.marginHeight = 10;

		body.setLayout(layout);
		
		GridData gd = new GridData();
		gd = new GridData(GridData.FILL_HORIZONTAL|GridData.VERTICAL_ALIGN_BEGINNING);
		gd.widthHint = 10;

		link = toolkit.createHyperlink(body, "Click here to login.", SWT.WRAP);
		link.setLayoutData(gd);
		link.addHyperlinkListener(new HyperlinkAdapter() {
			@Override
			public void linkActivated(@SuppressWarnings("unused") HyperlinkEvent e) {
	            LoginDialog loginDialog = new LoginDialog(getSite(), RequirementPlugin.getInstance());
	            loginDialog.open();
			}
		});
		link.setText("Log in");
	}

	
	@Override
	public void dispose() {
		super.dispose();
		link = null;
	}

	@Override
	public void setFocus() {
		link.setFocus();
	}

	@Override
	public void onModelUpdate(@SuppressWarnings("unused") IModelPersistable item) {}
	@Override
	public void onModelItemDeleted(@SuppressWarnings("unused") IModelPersistable item, INodeParent parent) {}
	@Override
	public void onNewModelItemCreated(@SuppressWarnings("unused") IModelPersistable item) {}
	@Override
	public void onModelChange(@SuppressWarnings("unused") IModelPersistable item) {}

}
